'''
'''

from PyQt4.QtCore import pyqtSignature
from PyQt4.QtGui import QDialog
from SimpleCells.Gui.Ui_SCDateSchedDialog import Ui_SCDateSchedDialog

try:
    import datetime
    import dateutil
    from dateutil import rrule
except ImportError:
    pass

class SCDateSchedDialog(QDialog,Ui_SCDateSchedDialog):
    ''''''
    
    FREQ = {'DAILY' : rrule.DAILY, 'WEEKLY' : rrule.WEEKLY,
            'MONTHLY' : rrule.MONTHLY, 'YEARLY' : rrule.YEARLY}
    
    def __init__(self,nDates,parent=None):
        QDialog.__init__(self,parent)
        self.setupUi(self)
        self.__nDates = nDates
        self.__dateList = []
        self.__fillDirection = None
    
    def __getDateList__(self):
        return self.__dateList
    dateList = property(__getDateList__)

    def __getFillDirection__(self):
        return self.__fillDirection
    fillDirection = property(__getFillDirection__)

    def accept(self):
        startDate = self.startDateEdit.date()
        startDate = datetime.date(startDate.year(),startDate.month(),startDate.day())
        freqStr = str(self.freqBox.currentText()).upper()
        if self.fillSelButton.isChecked():
            self.__dateList = list(rrule.rrule(freq=SCDateSchedDialog.FREQ[freqStr],
                                               dtstart=startDate,count=self.__nDates))
            self.__fillDirection = None
        else:
            endDate = self.endDateEdit.date()
            endDate = datetime.date(endDate.year(),endDate.month(),endDate.day())
            
            self.__dateList = list(rrule.rrule(freq=SCDateSchedDialog.FREQ[freqStr],
                                             dtstart=startDate,until=endDate))
            self.__fillDirection = str(self.dirBox.currentText().toLower())
        QDialog.accept(self)

if __name__ == '__main__':
    pass
